package com.cskaoyan.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

//当你引入对应的依赖的时候生效
@ConditionalOnClass(DruidDataSource.class)
@Configuration
public class DataSourceConfiguration {

    //容器中没有DataSource类型组件的时候生效 👉 生效的话@Bean生效 👉 注册DataSource组件
    @ConditionalOnMissingBean(DataSource.class)
    @Bean
    public DataSource dataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        return dataSource;
    }
}
